package com.crm.mapper;

import com.crm.vo.IndexStatisticsVo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDate;
import java.util.List;
import java.util.Map;

@Mapper
public interface ClueMapper {
    @Select("select count(id) from tb_clue where date(create_time) between #{beginCreateTime} and #{endCreateTime} ")
    Integer countAllClues(LocalDate beginCreateTime, LocalDate endCreateTime);
    @Select("select count(id) from tb_clue where status in(1,2) and date(create_time) between #{beginCreateTime} and #{endCreateTime}")
    Integer effectiveCluesNums(LocalDate beginCreateTime, LocalDate endCreateTime);

    @Select("SELECT DISTINCT(a.user_name) as name,COUNT(DISTINCT(a.assign_id)) num,c.dept_name FROM tb_assign_record a LEFT JOIN sys_user b ON a.user_name = b.user_name LEFT JOIN sys_dept c ON b.dept_id = c.dept_id WHERE a.type = 0 AND a.latest = 1 AND a.assign_id IN (SELECT DISTINCT(clue_id)FROM tb_business WHERE date(create_time) BETWEEN #{beginCreateTime} and #{endCreateTime})GROUP BY  name ORDER BY num DESC LIMIT 10;")
    List<Map<String, Object>> countAllClueByUser(IndexStatisticsVo indexStatisticsVo);
    @Select("select count(id) from tb_clue where date(create_time) between #{beginCreateTime} and #{endCreateTime}")
    Integer countAllClue(String beginCreateTime, String endCreateTime);
}
